package com.itheima.Test;

import com.itheima.domain.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;

public class Test01 {

    //无参方法
    @Test
    public void test1() {
        // 1  创建核心spring 容器IOC
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        // 2 从容器中获取bean对象
        User user = ac.getBean("user", User.class);
        user.eat();

    }

    //带参方法
    @Test
    public void test2() {
        // 1  创建核心spring 容器IOC
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        // 2 从容器中获取bean对象
        User user = ac.getBean("user1", User.class);
        user.play("lol", 33);
    }

    //类属性
    @Test
    public void test3() {
        // 1  创建核心spring 容器IOC
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        // 2 从容器中获取bean对象
        User user = ac.getBean("user2", User.class);
        System.out.println(user.getName());
        System.out.println(user.getAge());
        user.getLei().run();
        System.out.println(user.getBirthday());
    }

    //数据库-数据源
    @Test
    public void test4() {
        // 1 创建连接数据库连接池对象
        DruidDataSource ds = new DruidDatasource();
        // 2 设置连接数据库四大基本特征
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://192.168.236.129/db2");
        ds.setUsername("root");
        ds.setPassword("root");
        Connection connection = ds.getConection();
        System.out.println(connection);

    }

}



